<!doctype html>
<!--[if gt IE 8]><!--> <html class="no-js" lang=""> <!--<![endif]-->
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>学生端作业提交</title>
    <meta name="description" content="Ela Admin - HTML5 Admin Template">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/normalize.css@8.0.0/normalize.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/lykmapipo/themify-icons@0.1.2/css/themify-icons.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pixeden-stroke-7-icon@1.2.3/pe-icon-7-stroke/dist/pe-icon-7-stroke.min.css">
    <link rel="stylesheet" href="assets/css/cs-skin-elastic.css">
    <link rel="stylesheet" href="assets/css/lib/datatable/dataTables.bootstrap.min.css">
    <link rel="stylesheet" href="assets/css/style.css">

    <!-- <script type="text/javascript" src="https://cdn.jsdelivr.net/html5shiv/3.7.3/html5shiv.min.js"></script> -->
<!--引入axios类库，axios类库到哪里找呢？-->
		<!--到cdn资源库里去寻找?-->
		<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.20.0/axios.min.js"></script>
</head>
<body>
    <!-- Left Panel -->

    <aside id="left-panel" class="left-panel">
       <nav class="navbar navbar-expand-sm navbar-default">
       
       		<div id="main-menu" class="main-menu collapse navbar-collapse">
       			<ul class="nav navbar-nav">
       
       				<li class="menu-title">菜单</li><!-- /.menu-title -->
       				<li>
       					<a href="stu-dataOfClass.html"> <i class="menu-icon fa fa-users"></i>班级 </a>
       				</li>
       				<li>
       					<a href="stu-dataOfHomeworkinfo.html"> <i class="menu-icon fa fa-file-word-o"></i>已提交作业信息 </a>
       				</li>
       				<li>
       					<a href="stu-dataOfHomeworktask.html"> <i class="menu-icon fa fa-file-word-o"></i>未完成的课堂任务 </a>
       				</li>
       				<li class="menu-title">退出</li><!-- /.menu-title -->
       				<li>
       					<a href="login.html"> <i class="menu-icon fa fa-user-o"></i>退出登录 </a>
       				</li>
       			</ul>
       		</div><!-- /.navbar-collapse -->
       	</nav>
        </aside><!-- /#left-panel -->

    <!-- Left Panel -->

    <!-- Right Panel -->

    <div id="right-panel" class="right-panel">

        <!-- Header-->
        <header id="header" class="header">
            <div class="top-left">
                <div class="navbar-header">
                    <a class="navbar-brand" href="#"><i class="menu-icon fa fa-user-circle fa-2x"></i></a>
                </div>
            </div>
          
        </header><!-- /header -->
        <!-- Header-->

        <div class="breadcrumbs">
            <div class="breadcrumbs-inner">
                <div class="row m-0">
                    
                    
                </div>
            </div>
        </div>

        <div class="content">
            <div class="animated fadeIn">
                <div class="row">

                    <div class="col-md-12">
                        <div class="card">
                            <div class="card-header">
                                <strong class="card-title">作业提交</strong>
                            </div>
                            <div class="card-body">
								<div class="form-group"><label for="company" class=" form-control-label">作业标题</label>
								<input type="text" id="hwtitle"
									 placeholder="输入作业标题" class="form-control">
								</div>
								<div class="form-group"><label for="company" class=" form-control-label">作业文字内容</label>
								<textarea type="text"  id="hwtext"
									 placeholder="输入作业文字内容" class="form-control"></textarea>
								</div>
								
								<div class="form-group"><label for="company" class=" form-control-label"> </label>
									<input type="file" name="" id="homework" value="" />
								</div>
								
                            </div>
							
							<div class="card-body" align="center">
								<input type="button" class="btn btn-success" onclick="SubmitHomework()" value="提交">
								
							</div>
                        </div>
                    </div>


                </div>
            </div><!-- .animated -->
        </div><!-- .content -->


        <!-- /#right-panel -->

    <!-- Right Panel -->

    <!-- Scripts -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@2.2.4/dist/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.14.4/dist/umd/popper.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/js/bootstrap.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/jquery-match-height@0.7.2/dist/jquery.matchHeight.min.js"></script>
    <script src="assets/js/main.js"></script>


    
    <script src="assets/js/lib/data-table/dataTables.bootstrap.min.js"></script>
    <script src="assets/js/lib/data-table/dataTables.buttons.min.js"></script>
    <script src="assets/js/lib/data-table/buttons.bootstrap.min.js"></script>
    
    
    <script src="assets/js/lib/data-table/buttons.html5.min.js"></script>
    <script src="assets/js/lib/data-table/buttons.print.min.js"></script>
    <script src="assets/js/lib/data-table/buttons.colVis.min.js"></script>
    <script src="assets/js/init/datatables-init.js"></script>
	<script>
		function SubmitHomework(){
			var username=window.localStorage.getItem('SUsername');//login
			var title=document.getElementById('hwtitle').value;
			var note=document.getElementById('hwtext').value;
			var classid=window.localStorage.getItem('SselectClass');//stuclass
			var file = document.querySelector('input[type=file]').files[0];
			var number =window.localStorage.getItem('number');//stutask/stuinfo
			var write = document.getElementById('hwwrite');
			var ist = window.localStorage.getItem('ist');//0是修改 1是task
			var jobid= window.localStorage.getItem('jobid');
			//alert('现在正在提交的作业是：');
			console.log('ist:')
			console.log(ist);
			console.log('number:');
			
			console.log(number);
			console.log('jid:');
			console.log(jobid);
			console.log(username);
			console.log(title);
			console.log(note);
			console.log(classid);
			
			if(ist==1){
				let formData = new window.FormData();
				formData.append('file', file)	//可以为空
				formData.append('username', username)		//这里要改
				formData.append('title', title)
				formData.append('note', note)
				formData.append('classid', classid)		
				formData.append('number', number)				//本轮作业
				//task
				axios({
					method: "POST",
					url: "http://172.81.214.138:8000/uploader",
					headers: {
						'Content-Type': 'multipart/form-data' //注意这里
					},
				data: formData
				}).then((res) => {
					console.log(res);
					alert("提交成功");
					window.location.assign('stu-dataOfHomeworkinfo.html');
				}).catch((err) => {
					console.log(err)
				});
			}else{
				//job_up
				let formData = new window.FormData();
				formData.append('file', file)	//可以为空
				formData.append('title', title)		//这里要改
				formData.append('note', note)
				formData.append('jobid', jobid)
				//jobid
				//task
				axios({
					method: "POST",
					url: "http://172.81.214.138:8000/job_up",
					headers: {
						'Content-Type': 'multipart/form-data' //注意这里
					},
				data: formData
				}).then((res) => {
					console.log(res);
					alert("提交成功");
					window.location.assign('stu-dataOfHomeworkinfo.html');
					
				}).catch((err) => {
					alert("提交失败");
					console.log(err)
				});
			}
			
			
		}
		
	</script>

</body>
</html>
